<template>
    <div id="teamPage">
        <van-search v-model="searchText" placeholder="搜索队伍" @search="onSearch" />
        <TeamCardList :team-list="teamList" />
        <van-empty image="search" description="暂无数据" v-if="!teamList || teamList.length < 1" />
    </div>
</template>

<script setup lang="ts">

import router from '../router'
import TeamCardList from '../components/TeamCardList.vue'
import { onMounted, ref } from 'vue'
import myAxios from '../plugins/myAxios.ts'
import { showFailToast } from 'vant'

const searchText = ref("");

const teamList = ref([]);

/**
 * 搜索队伍
 * @param val
 */
const listTeam = async (val = '') => {
    try {
        const res = await myAxios.get("/team/list", {
            params: {
                searchText: val,
                pageNum: 1,
            }
        })
        if (res['code'] === 0) {
            teamList.value = res.data;
        } else {
            showFailToast("队伍信息获取失败")
        }
    } catch (error) {
        console.log("队伍信息获取失败", error);
        showFailToast("队伍信息获取失败")
    }
}

onMounted(async () => {
    listTeam();
})

const onSearch = (val) => {
    listTeam(val);
}

</script>

<style scoped>
#teamPage {

}
</style>